package com.my12306.train.utils;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @Author:苏牧夕
 * @Date:2020/8/28 16:12
 * @Version 1.0
 */
public class TrainUtils {
    public final static String dateStr = "yyyy-MM-dd HH:mm:ss";
    public static DateTimeFormatter formate = DateTimeFormatter.ofPattern(dateStr);


    /**
     * 计算时间的内置方法
     *
     * @param time
     * @param formate
     * @param number
     * @return
     */
    public static Date caclet(String time, DateTimeFormatter formate, int number) {
        LocalDateTime parse = LocalDateTime.parse(time, formate);
        ZoneId zone = ZoneId.systemDefault();
        Instant instant = parse.plusDays(number).atZone(zone).toInstant();
        Date date = Date.from(instant);
        return date;
    }
    public static String getDateStr(Date date,String dateStr){
        SimpleDateFormat strFormate = new SimpleDateFormat(dateStr);
        String format = strFormate.format(date);
        return format;
    }
}
